package com.skyline.jfs.namespace.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.skyline.jfs.namespace.model.JFSDirectory;

public class JFSDirectoryMapper implements RowMapper<JFSDirectory> {
	private static JFSDirectoryMapper mapper = new JFSDirectoryMapper();

	private final static String CREATED_TIME = "createdTime";
	private final static String EXIST = "exist";
	private final static String FILE_NUM = "fileNum";
	private final static String ID = "id";
	private final static String NAME = "name";
	private final static String PARENT = "parent";
	private final static String PATH = "path";
	private final static String PERMISSION = "permission";
	private final static String SUB_DIR_NUM = "subDirNum";
	private final static String UPDATE_TIME = "updateTime";

	public static JFSDirectoryMapper getMapper() {
		return mapper;
	}

	@Override
	public JFSDirectory mapRow(ResultSet rs, int rowNum) throws SQLException {
		//if(rs.next()==false) return null;
		JFSDirectory d = new JFSDirectory();
		d.setCreatedTime(rs.getTimestamp(CREATED_TIME));
		d.setExist(rs.getBoolean(EXIST));
		d.setFileNum(rs.getInt(FILE_NUM));
		d.setId(rs.getLong(ID));
		d.setName(rs.getString(NAME));
		d.setParent(rs.getLong(PARENT));
		d.setPath(rs.getString(PATH));
		d.setPermission(rs.getInt(PERMISSION));
		d.setSubDirNum(rs.getInt(SUB_DIR_NUM));
		d.setUpdateTime(rs.getTimestamp(UPDATE_TIME));
		return d;
	}

}
